<!DOCTYPE html>
<html>
  <head>
    <script src="../dist/jspsych.js"></script>
    <script src="../dist/plugin-image-slider-response.js"></script>
    <script src="../dist/plugin-preload.js"></script>
    <link rel="stylesheet" href="../dist/jspsych.css">
  </head>
  <body></body>
  <script>

    var jsPsych = initJsPsych({
      default_iti: 250, 
      on_finish: function() {
        jsPsych.data.displayData();
      }
    });

    // three images are used in a standard way in image-* plugins and can therefore be automatically preloaded.
    // there's one additional image ('img/happy_face_4.jpg') that is only used in timeline variables 
    // and will not be automatically preloaded, so this file must be preloaded manually.
    var preload = {
      type: jsPsychPreload,
      auto_preload: true, 
      images: ['img/happy_face_4.jpg']
    };

    // If render_on_canvas is false, the images will be shown via an <img> rather than <canvas> element.
    // In some browsers, the first time the images are shown, the <img> method (render_on_canvas: false) will produce a brief 
    // blank screen (white flash) between images that are presented consecutively with no post_trial_gap between them.
    var trial = {
      type: jsPsychImageSliderResponse,
      stimulus: jsPsych.timelineVariable('stim'),
      trial_duration: 1000,
      labels: ['1 (least happy)', '100 (most happy)'],
      prompt: '<p>How happy is this person on a scale of 1-100?</p><p>(Consecutive images with no post_trial_gap)</p>',
      response_ends_trial: false,
      slider_width: 500,
      stimulus_width: 400, 
      maintain_aspect_ratio: true,
      post_trial_gap: 0,
      //render_on_canvas: false 
    };

    var trial_proc = {
      timeline: [trial],
      timeline_variables: [ 
        {stim: 'img/happy_face_1.jpg'},
        {stim: 'img/happy_face_2.jpg'},
        {stim: 'img/happy_face_3.jpg'},
        {stim: 'img/happy_face_4.jpg'}
      ]
    };

    var trial_1 = {
      type: jsPsychImageSliderResponse,
      stimulus: 'img/happy_face_1.jpg',
      labels: ['1 (least happy)', '100 (most happy)'],
      slider_width: 500,
      require_movement: true,
      prompt: '<p>How happy is this person on a scale of 1-100? (Interaction with slider is required)</p>'
    };

    var trial_2 = {
      type: jsPsychImageSliderResponse,
      stimulus: 'img/happy_face_2.jpg',
      labels: ['1 (least happy)', '100 (most happy)'],
      slider_start: 80,
      slider_width: 500,
      prompt: '<p>How happy is this person on a scale of 1-100? (5s time limit; set start value)</p>',
      trial_duration: 5000
    };

    var trial_3 = {
      type: jsPsychImageSliderResponse,
      stimulus: 'img/happy_face_3.jpg',
      labels: ['1 (least happy)', '100 (most happy)'],
      slider_width: 500,
      prompt: '<p>How happy is this person on a scale of 1-100? (1s stimulus duration)</p>',
      stimulus_duration: 1000
    };

    jsPsych.run([preload, trial_proc, trial_1, trial_2, trial_3]);

  </script>
</html>